package com.central.apps.controller;

import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.central.apps.dao.QuickSearchDao;
import com.central.apps.entity.QuickSearch;
import com.central.common.web.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 快速搜索控制器
 *
 * @author JHY
 * @date 2023/01/16
 */
@Slf4j
@Api(tags = "快速检索")
@RestController
@RequestMapping("/quickSearch")
public class QuickSearchController {

    @Resource
    private QuickSearchDao searchDao;

    /**
     * 根据关键字查询文档
     *
     * @param map 参数map
     */
    @PostMapping("/queryAll")
    public Result<?> queryAll(@RequestBody Map<String, Object> map) {
        String keyword = MapUtil.getStr(map, "keyword");
        Integer pageNo = MapUtil.getInt(map, "pageNo");
        Integer pageSize = MapUtil.getInt(map, "pageSize");
        Page<QuickSearch> page = new Page<>(pageNo, pageSize);
        IPage<QuickSearch> list = searchDao.queryAll(page, keyword);
        return Result.succeed(list, "擦洗成功");
    }


}
